package org.truenewx.tnxjee.core.util;

import java.util.Locale;

import org.apache.commons.lang3.StringUtils;
import org.truenewx.tnxjee.core.Strings;

public class LocaleUtil {

    private LocaleUtil() {
    }

    /**
     * 判断字符串形式的值与指定区域对象是否匹配
     *
     * @param localeValue 字符串值
     * @param locale      区域
     * @return 是否匹配
     */
    public static boolean matches(String localeValue, Locale locale) {
        if (StringUtils.isBlank(localeValue)) {
            return Locale.getDefault().equals(locale);
        }
        String[] array = localeValue.split(Strings.UNDERLINE);
        if (!array[0].equals(locale.getLanguage())) {
            return false;
        }
        if (array.length > 1) {
            String country = locale.getCountry();
            return StringUtils.isNotBlank(country) && array[1].equals(country);
        }
        return true;
    }

}
